// pages/my/index.js
const app = getApp()
const HttpReq = require('@/utils/HttpReq.js')
import Toast from '@vant/weapp/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        show: false,
        id: '',
        Info: {},
        codeNum: '', //优惠券数量
        clientId: '',
        cardClientId: '',
        shopMobile: "", //商家电话
  
    },
    onOpen() {
        console.log("dsjkjdkf")
        this.setData({
            clientId: app.globalData.userInfo.id
        })
        this.setData({
            show: true
        });
    },
    //更多
    more() {
        wx.navigateTo({
            url: '/pageA/pages/more/index?id=' + this.data.Info.id + '&storeId=' + this.data.Info.storeId,
        })
    },
    //点击优惠券
    openCoupon() {
        console.log(23232);
        wx.navigateTo({
            url: `/pageA/pages/coupon/index?cardClientId=` + this.data.Info.id,
            complete: (res) => {
                console.log(res);
            },

        })
    },
    //拨打电话
    bdMobile() {
        wx.makePhoneCall({
            phoneNumber: this.data.shopMobile
        })
    },
    onClose() {
        this.setData({
            show: false
        });
    },
    //复购续费
    goGift() {
        wx.navigateTo({
            url: '/pageA/pages/makeCard2/makeCard2?dealType=3&cardId=' + this.data.Info.cardId + '&cardClientId=' + this.data.Info.id,
        })

    },
    //消费记录
    report() {
        wx.navigateTo({
            url: '/pageA/pages/myCardClient/expenseCalender/expenseCalender?cardClientId=' + this.data.cardClientId,
        })
    },
    //跳转核卡页面
    tapHk() {
        wx.navigateTo({
            url: '/pageA/pages/myCardClient/myCardClient?cardClientId=' + this.data.id,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
 
        this.data.id = options.id;
        let url = app.globalData.hostIp + '/weixin/cardClient/' + this.data.id;
        HttpReq.httpsResquest(url, null, 'GET').then((res) => {
            this.setData({
                Info: res.data
            })
          
     
            let codeList = this.data.Info.couponList.split(',')
            this.data.cardClientId = this.data.Info.id;
            console.log(codeList);
            this.setData({
                codeNum: codeList.length
            })
            this.getShop();
            console.log(res);
        }).catch((err) => {
            console.log(err);
        })



        // console.log(app.globalData.userInfo.id)
        // this.setData({
        //     clientId: app.globalData.userInfo.id,
        //     headerImage: app.globalData.userInfo.headerImage,
        //     name: app.globalData.userInfo.name,
        //     nickName: app.globalData.userInfo.nickName
        // })
    },
    //获取店铺信息
    getShop() {
        let url2 = app.globalData.hostIp + '/weixin/store/' + this.data.Info.storeId;
        HttpReq.httpsResquest(url2, null, 'GET').then((res) => {
            this.setData({
                shopMobile: res.data.phoneNumber
            })
            console.log(res);
        }).catch((err) => {
            console.log(err);
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})